package org.mc.service;

import io.swagger.annotations.ApiParam;
import org.mc.api.test.TestQueryServiceV1;
import org.mc.api.user.UserQueryServiceV1;
import org.mc.common.data.ResultCode;
import org.mc.common.data.ResultData;
import org.mc.common.rest.HttpClientRest;
import org.mc.common.util.JSONUtils;
import org.mc.resolver.AuthUserId;
import org.mc.response.user.CustomerDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 用户查询服务
 *
 * @author zhangjinyang
 * @create 2017-11-13 15:09OOO
 **/
@RestController
public class TestQueryRestServiceV1 implements TestQueryServiceV1 {

    @Autowired
    private UserQueryServiceV1 userQueryServiceV1;

    @Autowired
    private HttpServletResponse httpServletResponse;

    @Override
    public ResultData<CustomerDTO> queryCustomer(@AuthUserId @ApiParam(value = "用户id", hidden = true) Long userId) {
        //CookieUtils.addCookie(httpServletResponse, "userId", "123456", 888888);
        //return userQueryServiceV1.queryCustomer(userId);
        System.out.println("queryCustomer");
        String url = "https://testapi.laiminet.com/api/basics/v1/open/config_param/zc/order/expire_minutes";

        for (int i = 0; i < 20; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int i = 0; i < 10000; i++) {
                        ResultData resultData = new HttpClientRest().get(url, ResultData.class);
                        if (resultData.getResult() != ResultCode.SUCCESS) {
                            System.out.println(JSONUtils.toJson(resultData));
                        } else {
                            System.out.println(resultData.getResult());
                        }
                    }
                }
            }).start();
        }

        return ResultData.ok();
    }
}
